# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/7/9
# @File : 186 D - Sum of difference.py
# https://atcoder.jp/contests/abc186/tasks/abc186_d

#去绝对值的操作为 排序 即可。
#试前几项找规律法。例如：a1 a2 a3 a4
N = int(input())
rate = [int(i) for i in input().split()]
rate.sort()
char = []
char.append(rate[0])
for i in range(1, N - 1):
    char.append(rate[i] + char[i - 1])
a = sum(char)
tag = []
rate.sort(reverse=True)
tag.append(rate[0])
for i in range(1, N - 1):
    tag.append(rate[i] + tag[i - 1])
b = sum(tag)
print(b - a)


#推导公式法：
N = int(input())
rate = [int(i) for i in input().split()]
rate.sort(reverse=True)  # 从大到小排序
char = []
char.append(rate[0])
for i in range(1, N):#预处理出前缀和序列
    char.append(rate[i] + char[i - 1])
n = N - 1
res = 0
for i in range(N):
    res += ((n - i) * rate[i] - char[n] + char[i])#公式推出来的式子
print(res)

"""
https://atcoder.jp/contests/abc186/editorial/423
公式推导手机有拍
"""




